from PyQt6.QtCore import QTimer, QEventLoop, QObject
from PyQt6.QtWidgets import QMessageBox, QApplication


class MyMessageBox(QObject):
    def __init__(self, title, message):
        super().__init__()
        self.title = title
        self.message = message

    @staticmethod
    def show(title, message):
        event_loop = QEventLoop()
        message_box = MyMessageBox(title, message)
        message_box.destroyed.connect(event_loop.quit)
        message_box.ready_show()
        event_loop.exec()

    def ready_show(self):
        self.moveToThread(QApplication.instance().thread())
        QTimer.singleShot(0, self.on_show)

    def on_show(self):
        QMessageBox.warning(None, self.title, self.message)
        self.deleteLater()